package com.example.base.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.base.R;
import com.example.base.bean.HomeThree;
import com.example.base.bean.Object;
import com.example.base.bean.SysThree;

import java.util.ArrayList;
import java.util.List;

public class SystemAdapter extends BaseAdapter {
  public SystemAdapter(Context context, List<SysThree> dataList) {
    this.dataList.addAll(dataList);
    this.context = context;
  }

  public List<SysThree> getDataList() {
    return dataList;
  }

  private List<SysThree> dataList = new ArrayList<>();
  private Context context;


  @Override
  public int getCount() {
    return dataList.size();
  }

  @Override
  public Object getItem(int position) {
    return null;
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    MyViewHolder myViewHolder;
    if (convertView == null) {
      myViewHolder = new MyViewHolder();
      LayoutInflater inflater = LayoutInflater.from(context);
      convertView = inflater.inflate(R.layout.list_view, null, true);
      myViewHolder.tv_from = convertView.findViewById(R.id.textview1);
      myViewHolder.tv_time = convertView.findViewById(R.id.textview2);
      myViewHolder.tv_title = convertView.findViewById(R.id.textview3);
      myViewHolder.tv_name = convertView.findViewById(R.id.textview4);
      convertView.setTag(myViewHolder);
    } else {
      myViewHolder = (MyViewHolder) convertView.getTag();
    }
    SysThree sysThree = dataList.get(position);
    myViewHolder.tv_from.setText(sysThree.getShareUser());
    myViewHolder.tv_time.setText(sysThree.getNiceShareDate());
    myViewHolder.tv_title.setText(sysThree.getTitle());
    myViewHolder.tv_name.setText(sysThree.getChapterName());
    return convertView;
  }


  public void setData(List<SysThree> data) {
    dataList.addAll(data);
  }


  class MyViewHolder {
    TextView tv_from;
    TextView tv_time;
    TextView tv_title;
    TextView tv_name;
  }
}
